#include "thr.h"
#include "stdio.h"
#include "unistd.h"

/* 线程实例都是全局的 */
	THR_HND thr1, thr2, thr3;

void* thrfunc(void* arg)
{	
	int* i = (int*)arg;
	char thrname[16]; sprintf(thrname, "thr_%d", *i);
	thr_property(thr_get_handle(pthread_self()), thrname);
	while(1)
	{
		printf("thread #%d is running.\n", *i);
		sleep(1);
	}
}

int main(int argc, char* argv[])
{
	int thr1_arg = 11;
	int thr2_arg = 22;
	int thr3_arg = 33;

	thr_construct(&thr1, thrfunc, (void*)&thr1_arg);
	thr_construct(&thr2, thrfunc, (void*)&thr2_arg);
	thr_construct(&thr3, thrfunc, (void*)&thr3_arg);

	// Ctrl+D 正常退出getchar()
	getchar();

	printf("thread1 running time: %s\n", thr_running_time(&thr1));
	printf("thread2 running time: %s\n", thr_running_time(&thr2));
	printf("thread3 running time: %s\n", thr_running_time(&thr3));

	thr_release(&thr1);
	thr_release(&thr2);
	thr_release(&thr3);
}